package org.walkerljl.practice.mock.mockito;

/**
 * @author: lijunlin
 */
public class SimpleExample {

//    @Test
//    public void verifyBehaviour() {
//        //模拟创建一个List对象
//        List mock = mock(List.class);
//        //使用mock的对象
//        mock.add(1);
//        mock.clear();
//        //验证add(1)和clear()行为是否发生
//        verify(mock).add(1);
//        verify(mock).clear();
//    }
//
//    @Test
//    public void when_thenReturn(){
//        //mock一个Iterator类
//        Iterator iterator = mock(Iterator.class);
//        //预设当iterator调用next()时第一次返回hello，第n次都返回world
//        when(iterator.next()).thenReturn("hello").thenReturn("world");
//        //使用mock的对象
//        String result = iterator.next() + " " + iterator.next() + " " + iterator.next();
//        //验证结果
//        assertEquals("hello world world",result);
//    }
//
//    @Test(expected = IOException.class)
//    public void when_thenThrow() throws IOException {
//        OutputStream outputStream = mock(OutputStream.class);
//        OutputStreamWriter writer = new OutputStreamWriter(outputStream);
//        //预设当流关闭时抛出异常
//        doThrow(new IOException()).when(outputStream).close();
//        outputStream.close();
//    }

}
